package com.gzist.aidemo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.ArrayList;
import java.util.List;

/**
 * Swagger2配置信息
 */

@Configuration
@EnableSwagger2WebMvc
public class Swagger2Config {
    private ApiInfo commonApiInfo() {
        return new ApiInfoBuilder()
                .title("AI功能demo-接口文档" )
                .description("公共接口" )
                .version("1.0" )
                .contact(new Contact("hzj" , "https://blog.csdn.net/m0_74958221?spm=1000.2115.3001.5343" , "2065501873@qq.com" ))
                .build();
    }

    @Bean
    public Docket commonApiConfig() {
        List<Parameter> pars = new ArrayList<>();
        ParameterBuilder tokenPar = new ParameterBuilder();
        tokenPar.name("adminId" )
                .description("用户token" )
                .defaultValue("1" )
                .modelRef(new ModelRef("string" ))
                .parameterType("header" )
                .required(false)
                .build();
        pars.add(tokenPar.build());

        Docket adminApi = new Docket(DocumentationType.SWAGGER_2)
                .groupName("公共接口" )
                .apiInfo(commonApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.gzist.aidemo.controller" ))
                .paths(PathSelectors.regex(".*" ))
                .build()
                .globalOperationParameters(pars);
        return adminApi;
    }

}

